import random
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium_stealth import stealth

from config import ua

opt = webdriver.ChromeOptions()

opt.add_experimental_option("excludeSwitches", ["enable-automation"])
opt.add_experimental_option('useAutomationExtension', False)


def get_driver(url, user_agent=ua):
    try:
        opt.add_argument(f'--user-agent={random.choice(user_agent)}')
        driver = webdriver.Chrome(service=Service('/home/iridum/Projects/Work_find_date_of_makrs_cpmpany/chromedriver'),
                                  options=opt)
        driver.get(url=url)
        stealth(driver,
                languages=['en-US', 'en'],
                vendor='Google Inc',
                platform='Win32',
                webgl_vendor='Intel Inc.',
                renderer='Intel Iris OpenGL Engine',
                fix_hairline=True)
        return driver
    except Exception as ex:
        print(f'{ex} | get_links_pages')
